<template>
	<view class="container">
		<view class="container-background">
			<u-navbar :autoBack="true" leftIconColor="#FFFFFF" bgColor="transparent" @leftClick="onClickLeft">
				<template #center>
					<view style="color: #ffffff;">{{title}}</view>
				</template>
			</u-navbar>
			<view style="height: 74px;"></view>
			<view class="container-background-number">{{Math.round(taskObj.score)}}</view>
			<view class="container-background-better">得分率{{Math.round(taskObj.score)}}%</view>
		</view>
		<!-- 占位盒子 -->
		<view class="fillBox"></view>
		<view class="container-task">
			<view class="container-task-context">
				<view>单词个数</view>
				<view>{{taskObj.question_num}}</view>
			</view>
			<view class="container-task-context">
				<view>跟读用时</view>
				<view>{{taskObj.use_time}}</view>
			</view>

			<view class="container-task-expression">
				<view>
					<img src="@/assets/phoneticPractice/编组@3x.png" />
					<span>{{taskObj.green}}个</span>
				</view>
				<view>
					<img src="@/assets/phoneticPractice/编组备份@3x.png" />
					<span>{{taskObj.yellow}}个</span>
				</view>
				<view>
					<img src="@/assets/phoneticPractice/编组备份 2@3x.png" />
					<span>{{taskObj.red}}个</span>
				</view>
			</view>
		</view>
		<view class="container-fraction" v-for="item in taskObj.json" :key="item.id" @click="playAudio(item.video)">
			<view class="container-fraction-top">
				<view class="container-fraction-top-left">
					<view :class="item.score>=80? 'autoGreed': ''">{{item.words}}</view>
					<view>[{{item.symbol}}]</view>
					<view>{{item.pretations}}</view>
				</view>
				<img v-show="item.score<60" src="@/assets/phoneticPractice/声音-红@3x.png" />
				<img v-show="item.score>60 && item.score<80" src="@/assets/phoneticPractice/声音-黄@3x.png" />
				<img v-show="item.score>=80" src="@/assets/phoneticPractice/声音-绿@3x.png" />
			</view>
			<view class="container-fraction-bottom">
				<view class="container-fraction-bottom-left">
					<view>
						完整度：<span
							:class="item.integrity < 60 ? 'autoRed' : item.score < 80 ? 'autoYellow' : 'autoGreed'">{{item.integrity}}</span>
					</view>
					<view>
						流利度：<span
							:class="item.fluency < 60 ? 'autoRed' : item.score < 80 ? 'autoYellow' : 'autoGreed'">{{item.fluency}}</span>
					</view>
					<view>
						准确度：<span
							:class="item.accuracy < 60 ? 'autoRed' : item.score < 80 ? 'autoYellow' : 'autoGreed'">{{item.accuracy}}</span>
					</view>
				</view>
				<view class="container-fraction-bottom-right"
					:class="item.score < 60 ? 'autoRed' : item.score < 80 ? 'autoYellow' : 'autoGreed'">{{item.score}}
				</view>
			</view>
		</view>
		<!-- <audio ref="audioElement" :src="audioSrc" @ended="playEnded" preload="auto"></audio> -->
	</view>
</template>

<script setup>
	export default {
		data() {
			return {
				title: null,
				taskObj: {}
			}
		},
		onLoad(options) {
			if (options && options.title) {
				this.title = options.title
				uni.setNavigationBarTitle({
					title: this.title
				})
				let phoneticPractice = uni.getStorageSync('phoneticPracticeWord')
				this.taskObj = JSON.parse(phoneticPractice)
			}
		},
		methods: {
			//完成任务
			onClickLeft() {
				uni.navigateBack({
					delta: 1
				})
			},
			playAudio(audioUrl) {
				this.audioElement = uni.createInnerAudioContext();
				this.audioElement.src = audioUrl
				this.audioElement.autoplay = true;
			},
		}
	}
</script>

<style scoped lang="scss">
	.container {
		background: #F5F5F5;
		padding-bottom: 10px;
		height: 100%;
		overflow: scroll;

		.container-background {
			color: #FFFFFF;
			background: url('@/assets/phoneticPractice/背景@3x (1).png');
			background-size: contain;
			width: 100%;
			height: 280px;
			text-align: center;
			position: fixed;
			top: 0;

			.container-background-number {
				font-size: 66px;
				line-height: 97px;
			}

			.container-background-better {
				margin-top: 10px;
				font-size: 18px;
			}

			.container-background-submitTask {
				margin-top: 30px;
				font-size: 18px;
				display: flex;
				justify-content: center;
				align-items: center;

				img {
					width: 18px;
					height: 18px;
					margin-left: 10px;
				}
			}
		}

		.fillBox {
			height: 10px;
			padding-top: 280px;
		}

		.container-task {
			padding: 10px;
			// height: 160px;
			color: #333333;
			font-size: 16px;
			line-height: 53px;
			border-radius: 15px;
			background: #ffffff;
			margin: 10px;

			.container-task-context {
				border-bottom: 1px solid #E5E5E5;
				display: flex;
				justify-content: space-between;
			}

			.container-task-expression {
				display: flex;
				justify-content: space-around;
				align-items: center;

				view {
					display: flex;
					align-items: center;
				}

				img {
					width: 24px;
					height: 24px;
					margin-right: 10px;
				}

			}

		}

		.container-fraction {
			padding: 15px;
			color: #8E8E8E;
			font-size: 14px;
			border-radius: 15px;
			background: #ffffff;
			margin: 10px;

			.container-fraction-top {
				// margin: 10px 10px 0 10px;
				line-height: 20px;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.container-fraction-top-left {
					display: flex;
					align-items: center;

					view:nth-child(1) {
						color: #333333;
						font-weight: bold;
					}

					view:nth-child(2),
					view:nth-child(3) {
						margin-left: 10px;
					}
				}

				img {
					width: 18px;
					height: 14px;
				}

			}

			.container-fraction-bottom {
				// margin: 0 10px 15px 10px;
				line-height: 20px;
				margin-top: 10px;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.container-fraction-bottom-left {
					display: flex;
					align-items: center;

					view:nth-child(2),
					view:nth-child(3) {
						margin-left: 15px;
					}

					span {
						color: #FA192C;
					}
				}

				.container-fraction-bottom-right {
					color: #FA192C;
				}
			}
		}
	}


	.autoRed {
		color: #FA192C !important;
	}

	.autoYellow {
		color: #FF9917 !important;
	}

	.autoGreed {
		color: #0CB76C !important;
	}
</style>